<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>JS表达式运算——简易版本</title>
</head>
<body>
  <h1>请使用Chrome并按F12进行调试和测试</h1>
  <pre>
    var context = new CalContext();

    //获取值
    //var result = context.calc(expr);

    //下面是测试用例

    context.test("40+8*2",56);

    context.test("40*8+2",322);

    context.test("40/8+2",7);

    context.test("40+8/2",44);

    context.test("(40+8)/2",24);

    context.test("40*(8-2)",240);

    context.test("0.1 + 1 + 0.3",1.4);

    context.test("0.1 *10 + 6.3",7.3);

    context.test("$a + 5",10);  

    context.test("($a + 1)/2 + 1",4);

  </pre>
<script type="text/javascript" src="expression_simple.js"></script>
<script>
    var context = new CalContext();
    //增加值栈——变量
    context.putData("$a",5);

    context.test("40+8*2",56);

    context.test("40*8+2",322);

    context.test("40/8+2",7);

    context.test("40+8/2",44);

    context.test("(40+8)/2",24);

    context.test("40*(8-2)",240);

    context.test("10%3 + 1",2);

    context.test("0.1 + 1 + 0.3",1.4);

    context.test("0.1 *10 + 6.3",7.3);

    context.test("$a + 5",10);

    context.test("($a + 1)/2 + 1",4);
</script>
</body>
</html>